package com.hejia.bulbul.controller;

import java.util.List;

import com.hejia.alauda.entity.BankInfo;
import com.hejia.alauda.service.PaymentService;
import com.hejia.alauda.service.ConfigureService;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;

/**
 * 
 * 设置/银行设置
 *
 *
 * Created by showone on 2014 下午5:12:35.
 */
@Controller
@RequestMapping("setting/bank")
public class SettingBankController extends BaseController {

	@Resource
	private ConfigureService parameterService;

	@Resource
	private PaymentService bankInfoService;

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list(ModelMap model) {
		List<BankInfo> list = bankInfoService.findAllBankInfo();

		model.put("list", list);
		return "/setting/bank";
	}

	/**
	 * 跳转到修改界面
	 */
	@RequestMapping(value = "update/{id}", method = RequestMethod.GET)
	public String update(@PathVariable Long id, ModelMap model) {
		BankInfo bankInfo = bankInfoService.getBankInfoById(id);

		model.put("bankInfo", bankInfo);

		return "/setting/bankEdit";
	}

	@RequestMapping(value = "update", method = RequestMethod.POST)
	public String update(BankInfo bankInfo, ModelMap model,
			RedirectAttributes redirectAttributes) {
		if (bankInfoService.modifyBankInfo(bankInfo)) {
			redirectAttributes.addFlashAttribute("status", STATUS_SUCCESS);
			redirectAttributes.addFlashAttribute("msg", "银行信息修改成功");
		} else {
			redirectAttributes.addFlashAttribute("status", STATUS_FAILD);
			redirectAttributes.addFlashAttribute("msg", "银行信息修改失败");
		}

		return "redirect:/setting/bank/list";
	}
}
